<template>
  <el-dialog :title="title" :visible="state" @close="closeDialog">
    <el-form :model="data">
      <el-form-item label="会员姓名" :label-width="formLabelWidth">
        <el-input v-model="data.vip_name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="会员电话" :label-width="formLabelWidth">
        <el-input v-model="data.vip_phone" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="会员总消费金额" :label-width="formLabelWidth">
        <el-input
          v-model="data.vip_total_consume"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="会员折扣系数" :label-width="formLabelWidth">
        <el-select v-model="data.vip_discount" placeholder="请选择折扣系数">
          <el-option label="无" value="0"></el-option>
          <el-option label="5折" value="5.0"></el-option>
          <el-option label="69折" value="6.9"></el-option>
          <el-option label="79折" value="7.9"></el-option>
          <el-option label="89折" value="8.9"></el-option>
          <el-option label="95折" value="9.5"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="noBtn">取 消</el-button>
      <el-button type="primary" @click="yesBtn">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import * as api from "../utils/api";
export default {
  name: "ylDialog",
  computed: {
    mystate() {
      console.log(this.data);
      return this.state;
    },
  },
  props: ["state", "data", "title"],
  data() {
    return {
      formLabelWidth: "120px",
    };
  },
  methods: {
    noBtn() {
      if (this.title === "添加会员") {
        this.$emit("onSubmit", "dialogFormVisible");
      } else{
        this.$emit("noSubmit", "updatetankuang");
      }
    },
    yesBtn() {
      console.log(this.data);
      if (this.title === "添加会员") {
        this.$emit("noSubmit", "addtankuang");
        this.axios({
          method: "post",
          url: api.ADDMEMBERVIP,
          data: this.data,
        }).then((data) => {
          console.log(data);
          if (data.data.code === 200) {
            this.$emit("xuanran");
          }
        });
      } else {
        this.$emit("noSubmit", "dialogFormVisible");
        this.axios({
          method: "post",
          url: api.UPDATE_VIP,
          data: this.data,
        }).then((data) => {
          console.log(data);
          if (data.data.code === 200) {
            this.$emit("xuanran");
          }
        });
      }
    },
    closeDialog() {
      if (this.title === "添加会员") {
        this.$emit("noSubmit", "addtankuang");
      } else if (this.title === "修改会员") {
        this.$emit("noSubmit", "dialogFormVisible");
      }
    },
  },
};
</script>